//
//  LoadMoreTableFooter.m
//  MaiQuan
//
//  Created by ZHANG Tianle on 5/24/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "LoadMoreTableFooter.h"

@interface LoadMoreTableFooter()

@property (retain, nonatomic) IBOutlet UIActivityIndicatorView *loadingActivityIndicator;
@property (retain, nonatomic) IBOutlet UILabel *loadingMessageLabel;
@property (retain, nonatomic) IBOutlet UIButton *loadMoreButton;

@end

@implementation LoadMoreTableFooter

@synthesize loadingActivityIndicator = _loadingActivityIndicator;
@synthesize loadingMessageLabel = _loadingMessageLabel;
@synthesize loadMoreButton = _loadMoreButton;
@synthesize loadMoreTableDelegate = _loadMoreTableDelegate;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        // Initialization code
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)dealloc 
{
    self.loadingActivityIndicator = nil;
    self.loadingMessageLabel = nil;
    
    [_loadMoreButton release];
    [super dealloc];
}

- (void)changeToLoadingMode:(NSString*)loadingString
{
    [self.loadingActivityIndicator startAnimating];
    
    self.loadingMessageLabel.text = loadingString;
    [self addSubview:self.loadingMessageLabel];
    
    [self.loadMoreButton removeFromSuperview];
}

- (void)changeLoadMoreMode:(NSString*)loadMoreString
{
    [self.loadingActivityIndicator stopAnimating];

    self.loadingMessageLabel.text = loadMoreString;
    [self.loadingMessageLabel removeFromSuperview];
    
    [self.loadMoreButton setTitle:loadMoreString forState:UIControlStateNormal];
    [self addSubview:self.loadMoreButton];
}

- (IBAction)onClickLoadMore:(id)sender 
{
    if (self.loadMoreTableDelegate) 
    {
        [self.loadMoreTableDelegate onClickLoadMore];
    }
}

@end
